package com.tadpole.music.view.widget;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.tadpole.music.R;

import razerdp.basepopup.BasePopupWindow;

/**
 * 二维码弹窗
 * Created By 孙岩
 * on 2020/10/9
 */
public class QRCodePopup extends BasePopupWindow implements View.OnClickListener {
    //二维码
    private XCRoundRectImageView ivImage;
    //
    private ImageView ivClose;

    public QRCodePopup(Context context, Bitmap image) {
        super(context);
        ivImage = (XCRoundRectImageView) findViewById(R.id.ivImage);
        ivClose = (ImageView) findViewById(R.id.ivClose);
        ivClose.setOnClickListener(this);
        RequestOptions requestOptions = new RequestOptions()
                .placeholder(R.mipmap.app_icon)
                .error(R.mipmap.app_icon)
                .priority(Priority.HIGH)
                .diskCacheStrategy(DiskCacheStrategy.ALL);
        Glide.with(context).load(image).apply(requestOptions).into(ivImage);

    }

    @Override
    protected Animation initShowAnimation() {
        return null;
    }

    @Override
    public View getClickToDismissView() {
        return getPopupWindowView();
    }

    @Override
    public View onCreatePopupView() {
        return createPopupById(R.layout.pop_qrcode);
    }

    @Override
    public View initAnimaView() {
        return findViewById(R.id.rlCode);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.ivClose) {
            dismiss();
        }
    }
}
